//
//  EvaluationManageViewController.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/3/30.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "EvaluationManageViewController.h"
#import "EvaluationCell.h"
#import "UIColor+RandomColor.h"
#import "EvaluationStarView.h"
#import "CustomStarButton.h"
@interface EvaluationManageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;
@property (nonatomic ,strong) EvaluationStarView *starView;
@property (nonatomic ,strong) CustomStarButton *starSelectBtn;
@property (nonatomic ,strong) NSArray *dataSource;
@end

@implementation EvaluationManageViewController

- (NSArray *)dataSource {
    
    if (!_dataSource) {
        _dataSource = [NSArray array];
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
   
    [self createTableVeiwUI];
    [self createNarTitleViewUI];
   
}

- (void)createNarTitleViewUI {

    self.starSelectBtn = [[CustomStarButton alloc] init];
    [self.starSelectBtn setTitle:@"五星评价" forState:(UIControlStateNormal)];
    self.starSelectBtn.selected = NO;
    [self.starSelectBtn addTarget:self action:@selector(starSelectBtnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.titleView = self.starSelectBtn;
    
    self.starView = [[EvaluationStarView alloc] initWithFrame:(CGRectMake((size_width - 86)/2, 0, 86, 125)) andBtn:self.starSelectBtn];
        self.starView.alpha = 0;
    [self.view addSubview:self.starView];
}

- (void)starSelectBtnClicked:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        [UIView animateWithDuration:0.3 animations:^{
            _starView.alpha = 1;
            
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            _starView.alpha = 0;
        }];
    }
    
}

- (void)createTableVeiwUI {

    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, size_width, size_height - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 200;
    [self.view addSubview:self.tableView];
    
    UIView *headerView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, size_width, 8))];
    headerView.backgroundColor = [UIColor colorWithHexString:@"f2f2f2"];
    self.tableView.tableHeaderView = headerView;
    
    [self.tableView registerClass:[EvaluationCell class] forCellReuseIdentifier:@"EvaluationCell"];
}

#pragma mark - UITableView代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    EvaluationCell *cell = [EvaluationCell cellWithTableView:tableView];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [UIView animateWithDuration:0.3 animations:^{
        _starView.alpha = 0;
        self.starSelectBtn.selected = NO;
    }];


}

@end
